package Annotation;

import org.junit.Test;

import java.lang.reflect.Field;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/4/3 14:15
 * 说明：
 */

public class AnnotationTest {
    // 获取类声明上的注解
    @Test
    public void test1(){
        Class<Customer> clazz = Customer.class;
        //类型   名字     = 被注解的对象.getDeclaredAnnotation(注解类的名字.class)
        Table annotation = clazz.getDeclaredAnnotation(Table.class);

        // @Table(value = "t_customers")，获取的是value
        System.out.println(annotation.value());
    }

    // 获取属性声明的注解
    @Test
    public void test2() throws Exception {
        Class<Customer> clazz = Customer.class;

        Field nameField = clazz.getDeclaredField("name");

        // 获取属性上声明的注解
        Column nameColumn = nameField.getDeclaredAnnotation(Column.class);
        System.out.println(nameColumn.columnName()); // cust_name
        System.out.println(nameColumn.columnType()); // varchar(15)
    }
}
